#ifndef __OBJREADER_H
#define __OBJREADER_H

#include <fstream>
#include "Base.h"
#include "Mesh.h"

class ObjReader 
{
	
public:
	Mesh *readFile(const char * path);
	
	void split (int dim, const char parseChar, std::string &s, std::string *array)
	{
		int i = 0;
		for (int d = 0; d < dim - 1; d++) {
			int next = s.find(parseChar, i);
			if(next == -1) 
				break;			
			array[d] = s.substr(i,next-i);
			i = next+1;
		}
		array[dim-1] = s.substr(i, s.length());
	}
	
	FacePoint splitFace (const char parseChar, std::string &s)
	{		
		int i = 0;
		int points[3];
		for (int di = 0; di < 2; di++) {
			int next = s.find(parseChar, i);
			if(next == -1) 
				break;
				
			if (next - i <= 0)
				points[di] = -1;
			else {
				int number = atoi(s.substr(i, next-i).c_str());
				points[di] = number;
			}
			i = next+1;
		}
		points[2] = atoi(s.substr(i, s.length()).c_str());
		return FacePoint(points[0], points[1],points[2]);
	}
	
};

#endif